package com.yenlien.traceyun.business.controller;

import com.yenlien.traceyun.business.entity.StorageCuring;
import com.yenlien.traceyun.business.interceptor.UserAuthUtil;
import com.yenlien.traceyun.business.service.StorageCuringService;
import com.yenlien.traceyun.webase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by LiuSha on 2020/7/28.
 * 仓储养护管理
 */
@RestController
@RequestMapping("/storage/curing")
public class StorageCuringController extends BaseController {
    @Autowired
    private StorageCuringService storageCuringService;

    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody StorageCuring storageCuring) {
        storageCuring.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        return buildPage(storageCuringService.findByList(storageCuring));
    }
    // 生产调用的
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody List<StorageCuring> storageCuringList) {
        storageCuringService.save(storageCuringList, UserAuthUtil.getLoginUser().getCompanyId());
        return success("success");
    }

    // 种植调用的
    @RequestMapping(value = "/plantSave", method = RequestMethod.POST)
    public Object plantSave(@RequestBody StorageCuring storageCuring) {
        storageCuring.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        storageCuringService.plantSave(storageCuring);
        return success("success");
    }


    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Object update(@RequestBody StorageCuring storageCuring) {
        storageCuringService.update(storageCuring);
        return success("success");
    }

    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable String id) {
        return success(storageCuringService.findById(id));
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public Object delete(@PathVariable String id) {
        storageCuringService.delete(id);
        return success("success");
    }

    @RequestMapping(value = "/findByAll", method = RequestMethod.GET)
    public Object findByAll() {
        return success(storageCuringService.findByAll(UserAuthUtil.getLoginUser().getCompanyId()));
    }
}
